<?php if(!defined('DB_NAME')) die();

// 自定义文章标题，置顶, title, 最新发布
function ini_title( $sticky=1, $title=0, $news=1 ){
	global $post;
	$t1 = $post->post_date;
	$t2 = $post->post_modified;
	$t3 = date("Y-m-d H:i:s");
	$d = get('ini_new_post')? get('ini_new_post'): 3;
	$diff = ( strtotime($t3)-strtotime($t1) )/86400;    #以秒计算
	$diff2 = ( strtotime($t3)-strtotime($t2) )/86400;
	if( $sticky == 1 && is_sticky() && !get('ini_no_thumb') ) echo '<i class="top"></i>';
	else
	if( $diff < $d ){
		$new = '<i class="new"></i>';
	}
	else {
		if( ( get_the_modified_time('Y')*365+get_the_modified_time('z') ) > ( get_the_time('Y')*365 + get_the_time('z') ) && $diff2 < $d ){
			$new = '<i class="update"></i>';
		}
	}
	echo '<a href="'.get_permalink().'"'; if( $title == 1 ){ echo ' title="'.get_the_title().'"';} echo '>'.get_the_title().'</a>';
	if( $news == 1 && !get('ini_no_thumb') ) echo $new;
}

// 浏览次数
function get_post_views ($post_id){
	$count_key = 'views';
	$count = get_post_meta($post_id,$count_key,true);
	if ($count == ''){
		delete_post_meta($post_id,$count_key);
		add_post_meta($post_id,$count_key,'0');
		$count = '0';
	}
	return number_format($count);
}
function ini_post_views (){
	global $post;
	$post_id = $post -> ID;
	$count_key = 'views';
	$count = get_post_meta($post_id,$count_key,true);
	if ( is_single() || is_page() ){
		if ($count == ''){
			delete_post_meta($post_id,$count_key);
			add_post_meta($post_id,$count_key,'0');
		} else{
			update_post_meta($post_id,$count_key,$count + 1);
		}
	}
}
add_action('get_header','ini_post_views');

// 文章分页
function post_page(){
	if( is_single() && function_exists('themedie') or is_feed() ){
		$args = array('before'=>'<div class="pagination">', 'after'=>'</div>', 'link_before'=>'<i>', 'link_after'=>'</i>','next_or_number'=>'number');
		$page.= wp_link_pages($args);
	}
	return $page;
}

// 文章版权信息
function feed_copyright(){
	$custom = get_post_custom($post_id);
	$custom_cc = $custom['cc'];
	$custom_cc[0]!=""? $post_cc = "本文遵循 <a href=\"http://creativecommons.org/licenses/".strtolower($custom_cc[0])."/3.0/cn/\" rel=\"external nofollow\">$custom_cc[0]</a> 共享方式，": $post_cc = "";
	if( is_single() && !get('ini_mark') or is_feed() ){
		$Name = get_bloginfo('name');
			$content.= '<section class="post-meta"><div class="m-t">版权信息</div>'.$post_cc.'永久链接：<a href="'.wp_get_shortlink().'">'.wp_get_shortlink().'</a><br>转载请注明转自 » <a href="'.get_bloginfo("url").'" style="display:inline;">'.$Name.'</a> » <a href="'.wp_get_shortlink().'">'.get_the_title().'</a></section>';
	}
	return $content;
}

//百度分享
function ini_bdshare(){
	if( (get('ini_bdshare')&&get('ini_bds_btn')) && function_exists('themedie') && ( !ismobile() || ismobile()&&get('ini_mbds') ) ){
		echo '<div id="bdshare" class="bdsharebuttonbox"><span>分享到</span><a class="bds_tsina" data-cmd="tsina"></a><a class="bds_qzone" data-cmd="qzone"></a><a class="bds_weixin" data-cmd="weixin"></a><a class="bds_douban" data-cmd="douban"></a><a class="bds_twi" data-cmd="twi"></a><a class="bds_fbook" data-cmd="fbook"></a><a class="bds_more" data-cmd="more"></a></div><div class="clear"></div>';
	}
}

?>